<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增资源')" />
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-article-add">
            <div class="form-group">
                <label class="col-sm-3 control-label">资源名称：</label>
                <div class="col-sm-8">
                    <input name="articleName" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">资源内容：</label>
                <div class="col-sm-8">
                    <input id="articleContent" name="articleContent" type="hidden">
                    <div class="summernote"></div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">资源类别：</label>
                <div class="col-sm-8">
                    <select name="articleTypeId" class="form-control" th:with="type=${arc_type}">
                        <option th:each="arc : ${type}" th:text="${arc.srcTypeName}" th:value="${arc.srcTypeId}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">下载地址：</label>
                <div class="col-sm-8">
                    <input name="articleDownload1" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">密码：</label>
                <div class="col-sm-8">
                    <input name="articlePassword1" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">积分数：</label>
                <div class="col-sm-8">
                    <select name="articlePoints" class="form-control m-b" th:with="type=${@dict.getType('sys_article_points')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
        </form>
    </div>
    <div class="row">
        <div class="col-sm-offset-5 col-sm-10">
            <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: summernote-js" />
    <script type="text/javascript">
        var prefix = ctx + "content/article"

        $('.summernote').summernote({
            placeholder: '请输入资源描述内容',
            height : 192,
            lang : 'zh-CN',
            followingToolbar: false,
            callbacks: {
                onImageUpload: function (files) {
                    sendFile(files[0], this,0);
                }
            }
        });

        // 上传文件
        function sendFile(file, obj,flag) {
            var data = new FormData();
            data.append("file", file);
            $.ajax({
                type: "POST",
                url: ctx + "common/upload",
                data: data,
                cache: false,
                contentType: false,
                processData: false,
                dataType: 'json',
                success: function(result) {
                    if (result.code == web_status.SUCCESS) {
                        if (flag == 0){
                            $(obj).summernote('editor.insertImage', result.url, result.fileName);
                        }else if (flag == 1){
                            $(".note-link-url").val(result.fileName);
                        }
                    } else {
                        $.modal.alertError(result.msg);
                    }
                },
                error: function(error) {
                    $.modal.alertWarning("图片上传失败。");
                }
            });
        }


        $("#form-article-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                var sHTML = $('.summernote').summernote('code');
                $("#articleContent").val(sHTML);
                $.operate.save(prefix + "/add", $('#form-article-add').serialize());
            }
        }
    </script>
</body>
</html>